package com.dxy.yesas2020goals.study.partone.disignpattern.reposibilitypattern.withbuilder;

/**
 * @author victorydeng
 * @Classname Handler
 * @Description TODO
 * @Date 2020/5/13 9:24
 * @Created by victorydeng
 */
public abstract class Handler<T> {

    protected Handler next;

    abstract void doHandler(Member member);

    //维护下一个节点
    public void setNext(Handler next) {
        this.next = next;
    }
    public static class Builder<T> {
        //前一个节点
        private Handler<T> head;
        //后一个节点
        private Handler<T> tail;

        public Builder<T> addHandler( Handler handler){
            if (this.head == null) {
                this.head = this.tail = handler;
                return this;
            }
            this.tail.setNext(handler);
            this.tail = handler;
            return this;
        }
        public Handler<T> build(){
            return this.head;
        }
    }
}
